/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import dao.util.HibernateUtil;
import java.util.ArrayList;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Binhluan;
import pojo.Taikhoan;

/**
 *
 * @author vinh
 */
public class TaiKhoanDAO extends AbstractDAO<Taikhoan, String>{

    @Override
    protected Class getPoJoclass() {       
      return Taikhoan.class;
    }
    
    public Taikhoan getTaiKhoanByUsername(String username)
    {
        ArrayList<Taikhoan> danhsachtaikhoan;
        Session session = HibernateUtil.getSessionFactory().openSession();
        String hql = String.format("select obj from %s obj where obj.tendangnhap like '%s'", Taikhoan.class.getName(), username);
        Query query = session.createQuery(hql);
        danhsachtaikhoan = (ArrayList<Taikhoan>) query.list();
        session.close();
        return danhsachtaikhoan.get(0);
        
    }
}
